package com.zrz.resp.entity;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

public class ResponseListEntity<T>  {

    /** 是否有下一页 */
    private boolean hasNext = false;
    /** 总共有几项 */
    private Long totalCount;
    /** 具体的列表返回 */
    private List<T> list;
    /** 额外信息 */
    private Object extra;


    /**
     * 私有化构造函数
     * @author wangshuxiong
     * @since 2016/9/8 18:21
     */
    private ResponseListEntity() {

    }

    /**
     * 单例 创建值
     * @author wangshuxiong
     * @since 2016/9/8 17:23
     * @return  单例对象
     */
    public static <T> ResponseListEntity<T> newInstance() {
        return new ResponseListEntity();
    }

    public boolean isHasNext() {
        return hasNext;
    }

    public void setHasNext(boolean hasNext) {
        this.hasNext = hasNext;
    }

    public Long getTotalCount() {
        if (totalCount == null) {
            totalCount = list != null ? list.size() : 0L;
        }
        return totalCount;
    }

    public void setTotalCount(Long totalCount) {
        this.totalCount = totalCount;
    }

    public List<T> getList() {
        if (CollectionUtils.isEmpty(list)) {
            return Lists.newArrayList();
        }
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Object getExtra() {
        if (extra == null) {
            return Maps.newHashMap();
        }
        return extra;
    }

    public void setExtra(Object extra) {
        this.extra = extra;
    }
}